package com.xzh.homeliving.commodity.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xzh.homeliving.commodity.entity.AttrAtRelationEntity;
import com.xzh.homeliving.commodity.service.AttrAtRelationService;
import com.xzh.common.utils.PageUtils;
import com.xzh.common.utils.R;

import javax.annotation.Resource;


/**
 * 商品属性和商品属性组的关联表
 *
 * @author xzh
 * @email ranpis02@qq.com
 * @date 2024-01-31 20:34:54
 */
@RestController
@RequestMapping("commodity/attratrelation")
public class AttrAtRelationController {
    @Resource
    private AttrAtRelationService attrAtRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("commodity:attratrelation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrAtRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("commodity:attratrelation:info")
    public R info(@PathVariable("id") Long id){
		AttrAtRelationEntity attrAtRelation = attrAtRelationService.getById(id);

        return R.ok().put("attrAtRelation", attrAtRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("commodity:attratrelation:save")
    public R save(@RequestBody AttrAtRelationEntity attrAtRelation){
		attrAtRelationService.save(attrAtRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("commodity:attratrelation:update")
    public R update(@RequestBody AttrAtRelationEntity attrAtRelation){
		attrAtRelationService.updateById(attrAtRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("commodity:attratrelation:delete")
    public R delete(@RequestBody Long[] ids){
		attrAtRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/add/relation")
    public R addAttrAndAtRelation(@RequestBody AttrAtRelationEntity[] attrAtRelationEntities) {
        attrAtRelationService.addAttrAndAtRelation(attrAtRelationEntities);
        return R.ok();
    }
}
